Crate glib

source ·
Expand description

glib, gobject and gio bindings for Rust

This library contains

  • bindings to some essential GLib, GObject, GIO types and APIs,

  • common building blocks used in both handmade and machine generated bindings to GTK+ and other GLib-based libraries.

It is the foundation for higher level libraries with uniform Rusty (safe and strongly typed) APIs. It avoids exposing GLib-specific data types where possible and is not meant to provide comprehensive GLib bindings, which would often amount to duplicating the Rust Standard Library or other utility crates.

The library is a work in progress: expect missing functionality and breaking changes.

Dynamic typing

Most types in the GLib family have type identifiers (Type). Their corresponding Rust types implement the StaticType trait.

Dynamically typed Value can carry values of any T: StaticType.

Variant can carry values of T: StaticVariantType.

Errors

Errors are represented by Error, which can carry values from various error domains (such as FileError).

Objects

Each class and interface has a corresponding smart pointer struct representing an instance of that type (e.g. Object for GObject, gtk::Widget for GtkWidget). They are reference counted and feature interior mutability similarly to Rust’s Rc<RefCell<T>> idiom. Consequently, cloning objects is cheap and their methods never require mutable borrows. Two smart pointers are equal iff they point to the same object.

The root of the object hierarchy is Object. Inheritance and subtyping is denoted with the IsA marker trait. The Cast trait enables upcasting and downcasting.

Interfaces and non-leaf classes also have corresponding traits (e.g. ObjectExt and gtk::WidgetExt), which are blanketly implemented for all their subtypes.

Under the hood

GLib-based libraries largely operate on pointers to various boxed or reference counted structures so the bindings have to implement corresponding smart pointers (wrappers), which encapsulate resource management and safety checks. Such wrappers are defined via the glib_wrapper! macro, which uses abstractions defined in the wrapper, boxed, shared and object modules.

The translate module defines and partly implements conversions between high level Rust types (including the aforementioned wrappers) and their FFI counterparts.

Re-exports

pub use closure::Closure;
pub use error::Error;
pub use error::BoolError;
pub use object::Cast;
pub use object::IsA;
pub use object::Object;
pub use object::ObjectExt;
pub use object::WeakRef;
pub use object::SendWeakRef;
pub use signal::SignalHandlerId;
pub use signal::signal_handler_block;
pub use signal::signal_handler_disconnect;
pub use signal::signal_handler_unblock;
pub use types::StaticType;
pub use types::Type;
pub use value::ToValue;
pub use value::ToSendValue;
pub use value::TypedValue;
pub use value::SendValue;
pub use value::Value;
pub use value::AnyValue;
pub use value::AnySendValue;
pub use variant::StaticVariantType;
pub use variant::ToVariant;
pub use variant::Variant;
pub use send_unique::SendUniqueCell;
pub use send_unique::SendUnique;
pub use char::*;
pub use source::*;

Modules

IMPL Boxed wrapper implementation.
Error binding and helper trait.
IMPL Object wrapper implementation and Object binding.
Traits and essential types intended for blanket imports.
IMPL Shared (reference counted) wrapper implementation.
IMPL Low level signal support.
Translation between GLib/GLib-based FFI types and their Rust counterparts.
Runtime type information.
Value binding and helper traits.
Variant binding and helper traits.
IMPL The glib_wrapper! macro and miscellaneous wrapper traits.

Macros

Wrapper implementations for Boxed types. See glib_wrapper!.
Wrapper implementations for Object types. See glib_wrapper!.
Wrapper implementations for shared types. See glib_wrapper!.
Defines a wrapper type and implements the appropriate traits.

Structs

A shared immutable byte slice (the equivalent of Rc<[u8]>).
Representation of an enum for dynamically, at runtime, querying the values of the enum and using them.
Representation of a single enum value of an EnumClass.
Builder for conveniently setting/unsetting flags and returning a Value.
Representation of a flags for dynamically, at runtime, querying the values of the enum and using them
Representation of a single flags value of a FlagsClass.
A mutable text buffer that grows automatically.
Describes Variant types.
Describes Variant types.

Enums

Functions

basenameDeprecated

Type Definitions